<template>
  <!-- 添加或修改原材料（辅材）对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="来料检验批次号" prop="batchNumber">
                <el-input v-model="form.batchNumber" placeholder="请输入来料检验批次号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原材料制造商" prop="producer">
                <el-input v-model="form.producer" placeholder="请输入原材料制造商"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="样品编号" prop="sampleNumber">
                <el-input v-model="form.sampleNumber" placeholder="请输入样品编号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="检测结果" prop="detectionResult">
                <el-input style="width: 80%;" v-model="form.detectionResult" placeholder="请输入检测结果"/>
<!--                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='detectionResult'"-->
<!--                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}-->
<!--                </el-tag>-->
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="锌层厚度" prop="znThick">
                <el-input-number v-model="form.znThick" placeholder="请输入锌层厚度" :precision="3"/>
<!--                <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName==='znThick'"-->
<!--                        type="danger">{{ standard.propValueMin }}-{{ standard.propValueMax }}-->
<!--                </el-tag>-->
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="出厂检测日期" prop="leaveInspectDate">
                <el-date-picker clearable
                                v-model="form.leaveInspectDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择出厂检测日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="入厂检测日期" prop="arriveInspectDate">
                <el-date-picker clearable
                                v-model="form.arriveInspectDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择入厂检测日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否合格" prop="testPass">
                <el-radio-group v-model="form.testPass">
                  <el-radio
                    v-for="dict in dict.type.yes_no"
                    :key="dict.value"
                    :label="dict.value"
                  >{{ dict.label }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
<!--            <el-col :span="12">-->
<!--              <el-form-item label="质量证书" prop="qualityCertificate">-->
<!--                <file-upload v-model="form.qualityCertificate"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :span="12">
              <el-form-item label="生产厂检测报告" prop="singleStrength">
                <file-upload v-model="form.productReport"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="来料检测报告" prop="singleStrength">
                <file-upload v-model="form.materialReport"/>
              </el-form-item>
            </el-col>

          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';

export default {
  name: "FactoryMaterialAssistForm",
  dicts: ["yes_no"],
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // batchNumber: [
        //   {required: true, message: "来料检验批次号不能为空", trigger: "blur"}
        // ],
        // producer: [
        //   {required: true, message: "原材料制造商不能为空", trigger: "blur"}
        // ],
        // detectionResult: [
        //   {required: true, message: "样品编号不能为空", trigger: "blur"}
        // ],
        // sampleNumber: [
        //   {required: true, message: "检测结果不能为空", trigger: "blur"}
        // ],
        // znThick: [
        //   {required: true, message: "锌层厚度不能为空", trigger: "blur"}
        // ],
      },
      url: {
        getById: '/factoryMaterialAssist/factoryMaterialAssist/',
        add: '/factoryMaterialAssist/factoryMaterialAssist/add',
        edit: '/factoryMaterialAssist/factoryMaterialAssist/edit',
      },
      standardList: []
    };
  },
  created() {

  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        batchNumber: null,
        producer: null,
        sampleNumber: null,
        detectionResult: null,
        znThick: null,
        testPass: '1',
        leaveInspectDate: null,
        arriveInspectDate: null,
        qualityCertificate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加原材料（辅材）质量试验";
    },
    /** 新增按钮操作 */
    handleAddByWorkOrderId(workOrderId,goodsId,goodsSaleId) {
      this.reset();
      this.form.workOrderId = workOrderId;
      this.form.goodsId = goodsId;
      this.form.goodsSaleId = goodsSaleId;
      this.open = true;
      // this.getStandardList();
      this.title = "添加原材料（辅材）质量试验";
    },

    /** 新增按钮操作 */
    handleAddByDaohuoDetailId(daohuoDetailId,goodsId) {
      this.reset();
      this.form.daohuoDetailId = daohuoDetailId;
      this.form.goodsId = goodsId;
      // this.getStandardList();
      this.open = true;
      this.title = "添加原材料（辅材）质量试验";
    },

    /** 新增按钮操作 */
    handleAddByProduceDetailId(produceRecordDetailId,goodsId,goodsSaleId) {
      this.reset();
      this.form.produceRecordDetailId = produceRecordDetailId;
      this.form.goodsSaleId = goodsSaleId;
      this.form.goodsId = goodsId;
      // this.getStandardList();
      this.open = true;
      this.title = "添加原材料（辅材）质量试验";
    },

    /** 新增按钮操作 */
    handleAddBySampleId(sampleId, goodsId, goodsSaleId,materialId) {
      this.reset();
      this.form.sampleId = sampleId;
      this.form.goodsId = goodsId;
      this.form.goodsSaleId = goodsSaleId;
      this.form.materialId = materialId;
      // this.getStandardList();
      this.open = true;
      this.title = "添加原材料（辅材）质量试验";
    },





    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改原材料（辅材）";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.edit, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
    getStandardList() {
      let name = "factory_material_assist";
      let goodsId = this.form.goodsId;
      getAction('/factoryTestStandard/factoryTestStandard/getTableColumns/' + name + "/" + goodsId, {}).then(response => {
        this.loading = false;
        this.standardList = response.data;
      });
    },


  }
};
</script>
